package middleware

import (
	"net/http"
	"user_api/models/request"
	"user_api/models/response"

	"github.com/gin-gonic/gin"
)

func IsAdminAuth() gin.HandlerFunc {
	return func(c *gin.Context) {
		claims, _ := c.Get("claims")
		currentUser := claims.(*request.CustomClaims)
		if currentUser.AuthorityId != 1 {
			c.JSON(http.StatusForbidden, response.Response{
				Code:    http.StatusForbidden,
				Message: "当前用户没有权限",
			})
			c.Abort()
			return
		}
		c.Next()
	}
}

// IsPortalPorver 是否是PortalPorver
func IsPortalPorver() gin.HandlerFunc {
	return func(c *gin.Context) {
		claims, _ := c.Get("claims")
		currentUser := claims.(*request.CustomClaims)
		if currentUser.AuthorityId != 2 {
			c.JSON(http.StatusForbidden, response.Response{
				Code:    http.StatusForbidden,
				Message: "当前用户没有权限",
			})
			c.Abort()
			return
		}
		c.Next()
	}
}
